<?php

class Admin_Model_Register{
	
	private $registerTbl;
	
	public function __construct(){
		$this->registerTbl	= new Admin_Model_DbTable_Registers();
	}
	
	public function selectRegister($where=null,$order="dk.ngayDangKy"){
		$dbAdapter 	= Zend_Db_Table::getDefaultAdapter();
		$dbSelect	= new Zend_Db_Select($dbAdapter);
		$dbSelect->from(array('dk'=>'dangky'),'*')
				->joinInner(array('k'=>'khach'), 'dk.khachId = k.khachId',
						array('nguoiDaiDien','chucVu','toChuc','diaChi','dienThoai','email','fax','quocGia'))
				->joinInner(array('mn2'=>'menu2'), 'mn2.menu2Id = dk.menu2Id',array('tenMenu2','dangKyDV'))
				->joinInner(array('kv'=>'khuvucthue'), 'kv.khuVucId = dk.khuVucId','*');
				

		$where = ($where!=NULL) ? $where." and mn2.dangKyDV = 1" : " mn2.dangKyDV = 1";
		$dbSelect->where($where)->order($order);
		
		return $dbSelect;
	}
	
	public function addRegister($khachId, $menu2Id,$khuVucId, $ngayDuKien,$thoiGianThue,$dienTichThue,$mucDichThue,$ngayDangKy){
		$data = array(
			'khachId'		=>	$khachId,
			'menu2Id'		=>	$menu2Id,
			'khuVucId'		=>  $khuVucId,
			'ngayDuKien'	=>	$ngayDuKien,
			'thoiGianThue'	=>	$thoiGianThue,
			'dienTichThue'	=>	$dienTichThue,
			'mucDichThue'	=>	$mucDichThue,
			'ngayDangKy'	=>	$ngayDangKy
		);
		
		$this->registerTbl->insert($data);
	}
	
	public function addCutomRegister($data){
		$this->registerTbl->insert($data);
	}
	
	public function updateRegister($khachId, $menu2Id, $ngayDuKien,$thoiGianThue,$dienTichThue,$mucDichThue,$ngayDangKy,$where){
		$data = array(
			'ngayDuKien'	=>	$ngayDuKien,
			'thoiGianThue'	=>	$thoiGianThue,
			'dienTichThue'	=>	$dienTichThue,
			'mucDichThue'	=>	$mucDichThue,
			'ngayDangKy'	=>	$ngayDangKy
		);
		$this->registerTbl->update($data, $where);
	}
	
	public function updateCustomRegister($data,$where){
		$this->registerTbl->update($data, $where);
	}
	
	public function deleteRegister($where){
		$this->registerTbl->delete($where);
	}
	
	public function fetchAllRegister($where=NULL){
		if($where!=null)$this->registerTbl->fetchAll($where);
		else $this->registerTbl->fetchAll();
	}
	
	public function fetchRowRegister($where){
		$this->registerTbl->fetchRow($where);
	}
	
	
}

